<?php
namespace Home\Controller;
use Think\Controller;
class OrderController extends Controller {
    public function lists(){
		$name = session('name');
		$this->assign('name',$name);
		/* $res = M("shoping")->where("user='$name'")->select();
		foreach($res as $k=>$v){
			$arr[$k] = $v['pid'];
		}
		$data['pid'] = implode(',',$arr);
		$data['order_number'] = $name.$this->wyddh();
		$data['ueser'] = $name;
		$data['status'] = 1;
		M("order")->add($data); */
		
		$datas = M('spaddress')->where("user='$name'")->select();
		$this->assign("k",CONTROLLER_NAME);
		$this->assign("f",ACTION_NAME);
		$this->assign('datas',$datas);
		$this->display();
    }
	public function dingdan(){
		$name = session('name');
		$this->assign('name',$name);
		$res = M("shoping")->where("user='$name'")->select();
		foreach($res as $k=>$v){
			$arr[$k] = $v['pid'];
		}
		$data['pid'] = implode(',',$arr);
		$data['order_number'] = $name.$this->wyddh();
		$data['user'] = $name;
		$data['status'] = 1;
		M("order")->add($data);
	}
	public function wyddh(){
		return date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
	}
	public function qjsorder(){
		$name = session('name');
		$this->assign('name',$name);
		$this->assign("k",CONTROLLER_NAME);
		$this->assign("f",ACTION_NAME);
		$reslists = M('shoping')->where("user='$name'")->select();
		$this->assign('reslists',$reslists);
		$name = session('name');
		$data['price']=$reslists[0]['price'];
		$data['name']=$reslists[0]['title'];
		$data['user']=$name;
		$datas = M('spaddress')->where("username='$name'")->select();
		$this->assign('datas',$datas);
		
		$this->dingdan();
		$this->display();
	}
	
	public function ordersuccess(){
		$name =  session('name');
		$this -> assign('name',$name);
		$this->assign("k",CONTROLLER_NAME);
		$this->assign("f",ACTION_NAME);
		$datass = M("order")->where("user='$name'")->find();
		$this->assign('datass',$datass);
		$this->display();
	}
}